home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)win_multi.c V1.21 3/13/95";
- #endif
- /*
- | file name - win_multi.c
- |===================================================================
- |
- | This program demonstrates multiple window event gathering.
- |
- | This program demonstrates how to use the window event
- | routines to gather events from multiple windows. It uses
- | VOloWinEventPoll, which gets the next event from the queue,
- | regardless of which window it came from. Also, it shows how
- | a typical application might respond to some event types
- | such as V_RESIZE, V_EXPOSE, and V_WINDOW_QUIT.
- |
- | Events are passed to the event request handler so the input
- | objects will update. The graphs are updated only if the input
- | object took user input. In addition, this example shows how
- | to specify the dimensions and name of a window created using
- | TscOpenSet.
- |
- | In order to see a summary of the events on standard output
- | as they occur, rename the executable "win_eventsdb.x" and
- | invoke it from the command line.
- |
- | Generate a window QUIT event or type <q|Q> to exit.
- |
- |===================================================================
- */
- #include <windows.h>
- /*
- * DV-Tools header files
- */
- #include "std.h" /* <stdio.h> etc., scalar & macro definitions */
- #include "dvstd.h" /* public types & constants */
- #include "dvtools.h" /* constants used by T routines */
- #include "dvGR.h" /* constants used by window mgt & GR routines */
- #include "VOstd.h" /* constants used by VO & VOob routines */
- #include "Tfundecl.h" /* T routines (screens, drawports & views) */
- #include "VOfundecl.h" /* VO routines (objects) */
- #include "VUerfundecl.h" /* VUer routines (event handling routines) */
- #include "GRfundecl.h" /* GR routines (interface to display device) */
- #include "VUfundecl.h" /* VU routines (utilities) */
-
- /* Constants */
- #define DVPATH (char *)NULL
- #define DISPFORMS_STB (char *)NULL
- #define DVDEVICE (char *)NULL
- #define DVCOLORTABLE (char *)NULL
- #define SCREEN_VIEWPORT (RECTANGLE *)NULL
- #define DRAWING_VIEWPORT (RECTANGLE *)NULL
- #define WIN_MULTI_DBG "win_multidb.x"
- #define MAXWINS (int)2
-
- /* Define local variable containing view names and local funcation */
- char *view_name[MAXWINS] =
- {"multi1.v", "multi2.v"};
-
- /* Functions defined in win_multi.c */
- LOCAL ADDRESS drawnext_if_screen V_P_((DRAWPORT drawport, ADDRESS screen));
- /***************** End Function Declarations *************/
-
-
- /*
- * MAIN PROGRAM
- */
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- INT argc = 0;
- CHAR **argv;
-
- /*
- * program arguments
- * argv[1] - display device (default is DVDEVICE)
- */
-
- /* Define & initialize device name */
- char *device_name = DVDEVICE; /* default device name */
-
- /* Define display variables */
- OBJECT screen[MAXWINS]; /* display device, the window */
- DRAWPORT drawport[MAXWINS]; /* how & where to display picture */
- VIEW view[MAXWINS]; /* picture representation of the view file */
-
- /* Control loop variables */
- OBJECT location, /* the event representation */
- current_screen; /* current selected screen */
- WINEVENT *we; /* structure storing details of event */
- int event_req_status; /* status of event requests */
-
- /* Other variables */
- int screenx, /* new width of window in pixels */
- screeny, /* new height of window in pixels */
- i; /* index counter */
- int Quit = NO; /* flag to quit program */
-
-
- /*-----------------
- * Initialization
- *
- * TInit: perform the initialization of DV-Tools
- * TInit reads your configuration file and any
- * environment variables or logical names set.
- */
- make_argv(&argc,&argv,GetCommandLine());
- TInit( DVPATH, DISPFORMS_STB );
-
- if (argc > 1)
- device_name = argv[1];
- for (i = 0; i < MAXWINS; i++)
- {
- /*
- * TscOpenSet: opens a device as a screen object using
- * specified attributes
- *
- * Set exposure block to YES to insure the window is
- * ready for drawing when TdpDraw is called.
- */
- screen[i] = TscOpenSet (device_name, DVCOLORTABLE,
- V_WINDOW_WIDTH, 400,
- V_WINDOW_HEIGHT, 300,
- V_WINDOW_NAME, "win_multi",
- V_WINDOW_X, 150 * i,
- V_WINDOW_Y, i * 100,
- V_X_EXPOSURE_BLOCK, YES,
- V_ACTIVE_CURSOR,
- V_END_OF_LIST);
- if (!screen[i])
- {
- printf ("Must specify device on command line or");
- printf (" in DataViews configuration file.\n");
- S_EXIT (EXIT_ERR);
- }
-
- /*
- * VOscWinEventMask: sets the screen's window event mask
- */
- VOscWinEventMask ((ULONG) V_KEYPRESS | V_KEYRELEASE |
- V_BUTTONPRESS | V_BUTTONRELEASE |
- V_ENTERNOTIFY | V_MOTIONNOTIFY | V_LEAVENOTIFY |
- V_EXPOSE | V_RESIZE | V_WINDOW_QUIT,
- (ULONG) 0);
- /*
- * TviLoad: Load a view in from a file,
- * user supplied view or default view
- * TdpCreate: Create a drawport.
- * The drawport is attached to the screen object
- * specified while view specifies the view to be
- * displayed on the screen.
- */
- view[i] = TviLoad (view_name[i]);
- if (!view[i])
- {
- printf ("Could not load view from file ");
- printf ("%s.\n", view_name[i]);
- if (i == 0)
- TscClose (screen[0]);
- else
- {
- TdpDestroy (drawport[0]);
- TviDestroy (view[0]);
- TscClose (screen[0]);
- TscClose (screen[1]);
- }
- S_EXIT (EXIT_ERR);
- }
- drawport[i] = TdpCreate (screen[i], view[i],
- SCREEN_VIEWPORT, DRAWING_VIEWPORT);
-
- /*
- * TscErase: Erase the entire screen in the default
- * background color
- * TdpDraw: Draw the contents of the drawport
- */
- TscErase (screen[i]);
- TdpDraw (drawport[i]);
- }
-
- /*--------------------
- * Control loop
- *
- * Poll the event queue for window events specified by the
- * window mask in either of the screens. Set the current
- * screen based on where the event happened. Handle each
- * of the events as they happen. Events occurring within
- * input objects will be handled through the event request
- * handler VUerHandleLocEvent. Updates are performed if an
- * input object used the event.
- */
- FOREVER
- {
- /*
- * VOloWinEventPoll: Polls for the next window event.
- * The polling mode used is V_WAIT.
- * Therefore, VOloWinEventPoll does not
- * return until an event specified by
- * the mask is generated.
- */
- location = VOloWinEventPoll (V_WAIT);
-
- /*
- * VOloScreen: Get's the location object's screen object
- * VOscSelect: Selects screen as the current output device
- *
- * Set the current screen from the location object. The
- * current screen will be NULL if the location object pertains
- * to a DataViews widget input object. The DataViews event type
- * for a widget input object would be V_NON_DV_WINDOW_EVENT.
- */
- current_screen = VOloScreen (location);
- if (current_screen)
- VOscSelect (current_screen);
-
- /*
- * VOloType: returns the type of event. These types
- * match event types specified in VOscWinEventMask.
- */
- switch (VOloType (location))
- {
-
- case V_EXPOSE:
- /*
- * VOloRegion: Returns a rectangle representing the
- * exposed region on the screen.
- * TscRedraw: After erasing, redraws all the drawports
- * in the screen.
- * A portion of the window has been exposed and needs
- * to be redrawn.
- */
- TscRedraw (current_screen, VOloRegion (location));
- break;
-
- case V_RESIZE:
- /*
- * The window size has been changed.
- * TscReset: Resets all screen drawports after
- * window resizing
- * GRaspect_ratio: Gets the size of the screen in pixels
- *
- * Print the new size of the window to standard output.
- */
- TscReset (current_screen);
- GRaspect_ratio (&screenx, &screeny);
- printf ("Window Size: %d %d\n", screenx, screeny);
- break;
-
- case V_WINDOW_QUIT:
- /*
- * User requests a window quit.
- * Print message for quitting after V_WINDOW_QUIT
- */
- printf ("User Selected Window Quit...\n");
- Quit = YES;
- break;
-
- case V_KEYPRESS:
- /*
- * Check key selected.
- * VOloKeySym: Returns the key symbol value of the
- * location object
- * If the key symbol represents the characters 'q'
- * or 'Q' then quit the program.
- */
- switch (VOloKeySym (location))
- {
- case 'q':
- case 'Q':
- Quit = YES;
- break;
-
- default:
- break;
- }
- break;
-
- case V_KEYRELEASE:
- case V_BUTTONPRESS:
- case V_BUTTONRELEASE:
- case V_MOTIONNOTIFY:
- case V_NON_DV_WINDOW_EVENT:
- /*
- * VUerHandleLocEvent: Service the event.
- * This routine will check if the
- * event is used by any input objects
- * that are in the view.
- */
- event_req_status = VUerHandleLocEvent (location);
-
- /*
- * TdpForEachDrawport: Applies a function to all drawports,
- * in all screens.
- *
- * If an input object used the event, then update the
- * current screen if one has been set otherwise update
- * the first screen.
- */
- if (event_req_status != INPUT_UNUSED)
- if (current_screen)
- TdpForEachDrawport ((TDPTRAVERSEFUNPTR)drawnext_if_screen, (ADDRESS) current_screen);
- else
- TdpForEachDrawport ((TDPTRAVERSEFUNPTR)drawnext_if_screen, (ADDRESS) screen[0]);
- break;
-
- default:
- break;
-
- }
-
- /*
- * VOloWinEventGet: Returns the window event structure of
- * the location object.
- * VUweReportEvent: Reports window events at a specified
- * level of detail. Level 3 reports
- * information relevant to the event type.
- *
- * To report window event information, rename the executable
- * image of "win_multi.x" to "win_multidb.x". Invoke this
- * executable from the command line.
- */
- if (!strcmp (argv[0], WIN_MULTI_DBG))
- {
- we = (WINEVENT *) VOloWinEventGet (location);
- VUweReportEvent (we, (int)3);
- printf ("\n");
- }
-
- /* exit the program */
- if (Quit == YES)
- break;
- }
-
- /*--------------------
- * Termination
- *
- * VOscSelect: Selects screen as the current output device
- * TscErase: Erase the entire screen in the default
- * background color
- * TdpDestroy: Destroy the drawport,
- * TviDestroy: Destroy the view, freeing the allocated memory
- * TscClose: Closes a screen object's assoc. display device
- * TTerminate: Perform the clean-up for DV-Tools
- */
- printf ("Quitting...\n");
- for (i = 0; i < MAXWINS; i++)
- {
- VOscSelect (screen[i]);
- TscErase (screen[i]);
- TdpDestroy (drawport[i]);
- TviDestroy (view[i]);
- TscClose (screen[i]);
- }
- TTerminate ();
- return EXIT_OK;
- }
-
- /*---------------------
- *
- * drawnext_if_screen -- Update dynamics for all drawports
- * associated with the passed screen object.
- */
- /* ARGSUSED */
- LOCAL ADDRESS
- drawnext_if_screen (drawport, screen)
- DRAWPORT drawport;
- ADDRESS screen;
- {
- /*
- * TdpGetScreen: Gets the screen object of a drawport
- * TdpDrawNext: Updates all dynamic objects within a
- * drawport's view
- *
- * If the screen object associated with this drawport matches
- * the screen object passed in then updated the dynamics of this
- * drawport.
- */
- if ( (OBJECT)screen == TdpGetScreen (drawport))
- TdpDrawNext (drawport);
-
- return V_CONTINUE_TRAVERSAL;
- }
-